<?php
/**
 * @ClassName: DictDataLogic
 * @Description: TODO
 * @author: gydtrade
 * @Date: 2025-11-06 21:23
 * @Version: V1.0.0
 */

namespace app\common\logic;

use app\common\model;

class DictDataLogic
{
    function getConfig($key, $value)
    {
        $dictType = model\DictType::where('flag', $key)->find();

        if ($dictType) {
            $list = model\DictData::where('dict_type', $dictType['dict_type'])->order('sort,dict_value,id')->select();
            $arr = [];
            foreach ($list as $key => $item) {
                $arr[] = [
                    $item['dict_value'] => $item['dict_label']
                ];
            }

            if ($value === true) {
                return $arr;
            }

            $data = model\DictData::where('dict_type', $dictType['dict_type'])->where('dict_value', $value)->find();
            return $data['dict_label'] ?? '---';
        }

        return [];
    }

}